package com.paomi.client.fragment.shop.presenter;

import com.paomi.client.base.BaseLoadMorePresenter;
import com.paomi.client.base.BaseMvpLCEView;
import com.paomi.client.fragment.first.model.TicketJson;
import com.paomi.client.fragment.first.model.TicketListJson;
import com.paomi.client.net.Api;
import com.paomi.client.net.BaseCallback;
import com.paomi.client.net.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * Created by pc on 2018/10/25
 * Describe:周边列表
 * com.paomi.client.fragment.first.presenter
 */
public class ShopFraPre extends BaseLoadMorePresenter<BaseMvpLCEView> {
    private List<TicketJson> ticketList=new ArrayList<>();
    private int page1=1;
    private String content;
    private String type;
    public void setShopData(int page,String content,String type){
        page1=page;
        this.content=content;
        this.type=type;
        loadData(true);
    }
    @Override
    protected void loadData(int page, int skip, boolean pullToRefresh) {
        if (content != null) {
            Map<String, String> stringMap = new HashMap<>();
            stringMap.put("content", content);
            stringMap.put("pageNum", "" + page1);
            stringMap.put("pageSize", "" + Constants.PAGE_SIZE);
            stringMap.put("sort", type);
            Api.getInstanceService(Constants.Ticket_URL).getSearchTicket(stringMap).enqueue(new BaseCallback<TicketListJson>() {
                @Override
                public void onResponse(Call<TicketListJson> call, TicketListJson result) {
                    if (page == 1) {
                        ticketList.clear();
                    }
                    ticketList.addAll(result.getReturnData().getData());
                    getView().setData(ticketList, true);
                }
            });
        } else {
            getView().setData(ticketList, true);
        }
    }
}
